/**
 * @公司:公约树
 * @位置:苏州
 * @Classname AnimePropertyModel
 * @Date 2022-06-12 下午 12:52
 * @Created by hanWanLu
 * @auther 中文:韩万路
 */


package com.animeJava.mode;

import com.animeJava.dao.animeEvent.AnimeEventFinal;
import com.animeJava.dao.animeEvent.AnimeRender;
import com.animeJava.data.KeyData;
import com.animeJava.enumData.DirectionEnum;
import com.animeJava.util.AnimeException;

import java.util.*;

/**
 * 动画属性模型 包括过度动画 图片动画 以及帧动画
 */
public abstract class AnimeModel {
    private long            delay           =   0;	            //延时时间 单位毫秒 number, function (el, index, total)
    private long            endDelay        =   0;              //结束时的延时时间适用于 倒叙播放 和 来回播放
    private boolean         autoplay        =   false;          //是否自动创建执行	boolean
    private boolean         loop            =   false;          //是否循环播放	number, boolean
    private DirectionEnum   direction       =   DirectionEnum.NORMAL; //  '正常'	'倒叙', '来回' 播放时间轴
    private boolean         playOneKey      =   true;       //是否播放延时后第一帧
    private AnimeEventFinal begin;                          //动画开始
    private AnimeEventFinal complete;                       //动画渲染完成
    private KeyData         keyData;                        //当前动画单帧数据

    //动画工厂事件用于计算和返回事件
    public abstract long  animeFactory(long timeData , int FPS , AnimeRunStart animeRunStart ,
                                       AnimeEventFinal begin , AnimeRender update , AnimeEventFinal complete) throws AnimeException;




    public AnimeModel() {
    }
    public AnimeModel(HashMap<String , Object> params) {
        if(params != null){
            Set<Map.Entry<String, Object>> entries = params.entrySet();
            for (Map.Entry<String, Object> map: entries) {
                if("delay".equals(map.getKey()) && map.getValue() != null){
                    this.delay = (long) map.getValue();
                }
                if("autoplay".equals(map.getKey()) && map.getValue() != null){
                    this.autoplay = (boolean) map.getValue();
                }
                if("loop".equals(map.getKey()) && map.getValue() != null){
                    this.loop = (boolean) map.getValue();
                }
                if("direction".equals(map.getKey()) && map.getValue() != null){
                    this.direction = (DirectionEnum) map.getValue();
                }
                if("begin".equals(map.getKey()) && map.getValue() != null){
                    this.begin = (AnimeEventFinal) map.getValue();
                }
                if("complete".equals(map.getKey()) && map.getValue() != null){
                    this.complete = (AnimeEventFinal) map.getValue();
                }
            }
        }
    }


    public AnimeModel(long delay, boolean autoplay, boolean loop, DirectionEnum direction,  AnimeEventFinal begin, AnimeEventFinal complete) {
        this.delay = delay;
        this.autoplay = autoplay;
        this.loop = loop;
        this.direction = direction;
        this.begin = begin;
        this.complete = complete;
    }


    public long getDelay() {
        return delay;
    }

    public void setDelay(long delay) {
        this.delay = delay;
    }


    public boolean isAutoplay() {
        return autoplay;
    }

    public void setAutoplay(boolean autoplay) {
        this.autoplay = autoplay;
    }

    public boolean isLoop() {
        return loop;
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }

    public DirectionEnum getDirection() {
        return direction;
    }

    public void setDirection(DirectionEnum direction) {
        this.direction = direction;
    }


    public AnimeEventFinal getBegin() {
        return begin;
    }

    public void setBegin(AnimeEventFinal begin) {
        this.begin = begin;
    }


    public AnimeEventFinal getComplete() {
        return complete;
    }

    public void setComplete(AnimeEventFinal complete) {
        this.complete = complete;
    }

    public long getEndDelay() {
        return endDelay;
    }

    public void setEndDelay(long endDelay) {
        this.endDelay = endDelay;
    }

    public boolean isPlayOneKey() {
        return playOneKey;
    }

    public void setPlayOneKey(boolean playOneKey) {
        this.playOneKey = playOneKey;
    }

    public KeyData getKeyData(){
        return keyData;
    }

    protected void updateKeyData(KeyData keyData){
        this.keyData = keyData;
    }

}
